package com.example.day10_zuoye.utils;

import android.content.Context;
import android.content.SharedPreferences;

//单例模式
public class SPUtils {

    private SharedPreferences sharedPreferences;
    private SharedPreferences.Editor editor;


    private SPUtils(Context context){
        sharedPreferences = context.getSharedPreferences("1907A",Context.MODE_PRIVATE);
        editor = sharedPreferences.edit();
    }
    private static SPUtils spUtils;
    public synchronized static SPUtils getInstance(Context context){
        if(spUtils == null){
            spUtils = new SPUtils(context);
        }
        return spUtils;
    }

    //添加
    public void putString(String key,String value){
        editor.putString(key,value);
        editor.commit();
    }
    //获得
    public String getString(String key){
        return sharedPreferences.getString(key,"");
    }







}
